package so.shanku.essential.activity;

import android.content.Intent;
import android.view.View;
import com.unionpay.UPPayAssistEx;
import net.tsz.afinal.annotation.view.ViewInject;
import so.shanku.essential.R;
import so.shanku.essential.activity.base.BaseUIActivity;
import so.shanku.essential.utils.ExtraKeys;
import android.os.Bundle;
import android.widget.TextView;
import aym.util.json.JsonMap;
import aym.util.json.JsonParseHelper;
import so.shanku.essential.utils.StringUtil;


public class OrderResultActivity extends BaseUIActivity {

	/**
	 * 状态
	 */
	@ViewInject(id = R.id.order_confirm_tv_stutas)
	private TextView tv_stutas;
	/**
	 * 订单号
	 */
	@ViewInject(id = R.id.order_confirm_tv_ordernumber)
	private TextView tv_ordernumber;
	/**
	 * 共计
	 */
	@ViewInject(id = R.id.order_confirm_tv_total)
	private TextView tv_total;
	/**
	 * 详细状态
	 */
	@ViewInject(id = R.id.order_confirm_tv_note)
	private TextView tv_note;
	/**
	 * 订单详情
	 */
	@ViewInject(id = R.id.order_confirm_tv_detail, click = "order_confirm_tv_detail_click")
	private TextView tv_detail;
	private String result;
	private JsonMap<String, Object> data;
	/**
	 * 0成功，1失败
	 */
	private int resultCode = 0;
	private String orderNum;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_order_pay_result);
		result = getIntent().getStringExtra(ExtraKeys.Key_Msg1);
		data = JsonParseHelper.getJsonMap(result);
		resultCode = data.getInt("resultCode", 0);
		goOrderDetail(resultCode);
		orderNum = data.getStringNoNull("OrderNum");
		String productName = data.getStringNoNull("productName");
		String totalPrice = data.getStringNoNull("ActualPayPrice");
		tv_total.setText(getString(R.string.order_confirm_total_price) + StringUtil.getFormatMoneyWithSignMust(totalPrice));
		tv_ordernumber.setText(getString(R.string.order_confirm_order_number) + orderNum);
		boolean isInstallUnionPayPlugin = getIntent().getBooleanExtra(ExtraKeys.Key_Msg2, false);
		if (isInstallUnionPayPlugin) {
			UPPayAssistEx.installUPPayPlugin(this);
		}
	}

	private void goOrderDetail(int i) {
		if (i == 0) {
			setCenter_title(R.string.order_confirm_title_success);
			tv_stutas.setText(R.string.order_confirm_success);

			tv_note.setText(R.string.order_confirm_sending);
		} else {
			setCenter_title(R.string.order_confirm_title_no_success);
			tv_stutas.setText(R.string.order_confirm_no_success);
			tv_note.setText(R.string.order_confirm_nopay);
		}
	}

	/**
	 * 订单详情
	 *
	 * @param view
	 */
	public void order_confirm_tv_detail_click(View view) {
		Intent intent = new Intent(this, UserOrderActivity.class);
		intent.putExtra(ExtraKeys.Key_Msg1, orderNum);
		jumpTo(intent, true);
	}

}
